package de.bml.versandanzeige;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

public class StandortAnzeigenActivity extends Activity {
	private Standort standort;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.standort_ansicht);

		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			standort = Standort.get(extras.getLong(
					HauptActivity.STANDORT_EXTRA, 0));
			((TextView) findViewById(R.id.textView_StandortTitel))
					.setText(standort.getLabel());
			((TextView) findViewById(R.id.textView_StandortDetails))
					.setText(standort.getDetails());
			String idExtern = standort.getIdExtern();
			if (!idExtern.equals("")) {
				((TextView) findViewById(R.id.textView_StandortLabel))
						.setText(getResources().getString(
								R.string.zugeordnete_id)
								+ " " + idExtern);
				((TextView) findViewById(R.id.buttonZuordnen))
						.setText(R.string.button_neueIdZuordnen);
			}
		}
	}

	public void aktuellMachen(View view) {
		Standort.setAktuell(standort);
		finish();
	}

	public void idZuordnen(View view) {
		IntentIntegrator integrator = new IntentIntegrator(this);
		integrator.initiateScan();
		// TODO testen
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
		if (resultCode == Activity.RESULT_OK) {
			// If the request went well (OK) and the request was
			switch (requestCode) {
			case IntentIntegrator.REQUEST_CODE:
				IntentResult result = IntentIntegrator.parseActivityResult(
						requestCode, resultCode, intent);
				if (result != null) {
					String id = result.getContents();
					standort.setIdExtern(id);
					break;
				}
			}
		}
	}
}
